﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TpContracts;
using TpData.Layer;
using TpLogger;

namespace TpData.Manager {
    public class LogDataManager {

        #region Members
        #endregion

        #region Load
        #endregion

        #region Save

        public static void SaveLog(int userID, string logType, string logArea, string logDetails, bool isError) {
            SaveLog(userID, logType, logArea, logDetails, isError, new DateTime(1900, 1, 1));
        }

        public static void SaveLog(int userID, string logType, string logArea, string logDetails, bool isError, DateTime logDate) {
            using (LogDataLayer dl = CreateLogDataLayer()) {
                dl.SaveLog(userID, logType, logArea, logDetails, isError, logDate);
            }
        }

        public static void SaveLogObject(Logger log) {
            Logger l = new Logger();
            l.LogList = log.LogList;
            int userID = Contracts.MyUser.UserID;
            foreach (Logger.LogItem item in l.LogList) {
                SaveLog(userID, "Log", "TpData.Manager.LogDataManager", item.message, item.IsError, item.logDate);
            }
        }

        #endregion

        #region Functions

        private static LogDataLayer CreateLogDataLayer() {
            return (DataManager.CreateDataLayer(typeof(LogDataLayer)) as LogDataLayer);
        }

        #endregion
        
    }
}
